{extend name='main'}

{block name="button"}

{if auth("add_users")}
<!--<button data-modal='{:url("add_users")}' data-title="添加会员" class='layui-btn'>添加会员</button>-->
{/if}

{/block}

{block name="content"}

<div class="think-box-shadow">
    {include file='order/group_search'}
    <table class="layui-table" lay-filter="tab" lay-skin="line">
        {notempty name='list'}
        <thead>
        <tr>
            <th lay-data="{field:'id',width:80}" class='text-left nowrap'>ID</th>
<!--            <th lay-data="{field:'aid',width:80}" class='text-left nowrap'>代理ID</th>-->
            <th lay-data="{field:'name'}" class='text-left nowrap'>分组名</th>
            <th lay-data="{field:'status'}" class='text-left nowrap'>是否默认</th>
            <th lay-data="{field:'pay'}" class='text-left nowrap'>支付方式</th>
            <th lay-data="{field:'user_num',width:80}" class='text-left nowrap'>会员数量</th>
            <th lay-data="{field:'create_time',width:200}" class='text-left nowrap'>创建时间</th>
            <th lay-data="{field:'edit',width:280,fixed: 'right'}" class='text-left nowrap'>操作</th>
        </tr>
        </thead>
        {/notempty}
        <tbody>
        {foreach $list as $key=>$vo}
        <tr>
            <td class='text-left nowrap'>{$vo.id}</td>
<!--            <td class='text-left nowrap'>{$vo.aid}</td>-->
            
            <td class='text-left nowrap'>{$vo.name}</td>
            {switch vo.status}
            {case 1}<td class='text-left nowrap'><span class="color-green">是</span></td>{/case}
            {case 2}<td class='text-left nowrap'><span class="color-red">否</span></td>{/case}
            {/switch}
            <td class='text-left nowrap'>{$vo.pay}</td>
            <td class='text-left nowrap'>{$vo.id|group_num}</td>
            <td class='text-left nowrap'>{$vo.create_time|format_datetime}</td>
            <td class='text-left nowrap'>
                <a data-dbclick class="layui-btn layui-btn-xs" data-title="编辑菜单" data-modal='{:url("admin/order/group_edit")}?id={$vo.id}'>编 辑</a>
                <a data-dbclick class="layui-btn layui-btn-xs layui-btn-normal" data-title="编辑用户" data-modal='{:url("admin/order/group_user")}?id={$vo.id}'>用 户</a>

                <a data-dbclick class="layui-btn layui-btn-xs layui-btn-warm" data-title="编辑模板" data-modal='{:url("admin/order/group_mode")}?id={$vo.id}'>模 板</a>

                <a class="layui-btn layui-btn-xs layui-btn-danger" onClick="del_group({$vo.id})">删除</a>
            </td>
        </tr>
        {/foreach}
        </tbody>
    </table>

    <script>
        var table = layui.table;
        //转换静态表格
        var limit = Number('{$Think.get.limit}');
        if(limit==0) limit=20;
        table.init('tab', {
            cellMinWidth:120,
            skin: 'line,row',
            even: false,
            size: 'sm ',
            limit: limit
        });
    </script>

    <script>
        $(document).on("click", ".rollover", function (){
            var id = $(this).data('id');
            layer.prompt({title: '请输入续期小时数', formType: 3}, function(hour, index){
                layer.close(index);
                if (hour != null){
                    $.ajax({
                        url: "{:Url('order_rollover')}",
                        type: "post",
                        traditional: true,
                        data: {id:id,hour:hour} ,
                        success: function (e) {
                            if (e.code === 1){
                                layer.msg(e.msg, {
                                    time: 2000,
                                    end: function () {
                                        location.reload();
                                    }
                                });
                            }else {
                                layer.msg(e.msg, function(){
                                    return false;
                                });
                            }

                        },
                    });
                }
            });
        });

        $(document).on("click", ".release", function (){
            var id = $(this).data('id');
            layer.confirm('确定要解冻吗？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                $.ajax({
                    url: "{:Url('order_release')}",
                    type: "post",
                    traditional: true,
                    data: {id:id} ,
                    success: function (e) {
                        if (e.code === 1){
                            layer.msg(e.msg, {
                                time: 2000,
                                end: function () {
                                    location.reload();
                                }
                            });
                        }else {
                            layer.msg(e.msg, function(){
                                return false;
                            });
                        }
                    },
                });
            });
        });
    </script>

    <script>
        function del_group(id){
            layer.confirm("确认要删除吗，删除后不能恢复",{ title: "删除确认" },function(index){
                $.ajax({
                    type: 'POST',
                    url: "{:url('group_del')}",
                    data: {
                        'id': id,
                    },
                    success:function (e) {
                        if (e.code === 1) {
                            layer.msg(e.msg, {
                                time: 2000,
                                end: function () {
                                    location.reload();
                                }
                            });
                        } else {
                            layer.msg(e.msg, function () {
                                return false;
                            });
                        }
                    }
                });
            },function(){});
        }
    </script>

    {empty name='list'}<span class="notdata">没有记录哦</span>{else}{$pages|raw|default=''}{/empty}
</div>
{/block}
